package bb.lanxing.utils;

import java.util.List;

import bb.lanxing.lib.devices.sgsettingentity.setting.PanelDisplayData;
import bb.lanxing.lib.devices.sgsettingentity.setting.PanelModel;
import bb.lanxing.lib.devices.sgsettingentity.setting.PanelSportMode;

public class PanelModelToJsonUtil {
    public static String toJson(PanelModel PANEL_MODEL) {
        if (PANEL_MODEL == null) {
            return null;
        }
        String result = "{\"version\":\"" + PANEL_MODEL.getVersion()
                + "\",\"device_model\":\"" + PANEL_MODEL.getDevice_model()
                + "\",\"sn\":\"" + PANEL_MODEL.getSn()
                + "\",\"update_at\":\"" + PANEL_MODEL.getUpdate_at()
                + "\",\"profilesList\":[";
        List<PanelSportMode> profilesList = PANEL_MODEL.getProfilesList();
        for (int i = 0; i < profilesList.size(); i++) {
            result += "{\"target\":[";
            List<Integer> target = profilesList.get(i).getTarget();
            for (int j = 0; j < target.size(); j++) {
                result += target.get(j);
                if (j < target.size() - 1) {
                    result += ",";
                }
            }
            result += "],\"remind\":[";
            List<Integer> remind = profilesList.get(i).getRemind();
            for (int j = 0; j < remind.size(); j++) {
                result += remind.get(j);
                if (j < remind.size() - 1) {
                    result += ",";
                }
            }
            result += "],\"autopause\":" + profilesList.get(i).getAutopause() + ",\"autolap\":[";
            List<Integer> autolap = profilesList.get(i).getAutolap();
            for (int j = 0; j < autolap.size(); j++) {
                result += autolap.get(j);
                if (j < autolap.size() - 1) {
                    result += ",";
                }
            }
            result += "],\"manuallap\":[";
            List<Integer> manuallap = profilesList.get(i).getManuallap();
            for (int j = 0; j < manuallap.size(); j++) {
                result += manuallap.get(j);
                if (j < manuallap.size() - 1) {
                    result += ",";
                }
            }
            result += "],\"displayData\":[";
            List<PanelDisplayData> displayData = profilesList.get(i).getDisplayData();
            for (int j = 0; j < displayData.size(); j++) {
                PanelDisplayData panelDisplayData = displayData.get(j);
                result += "{\"panelId\":" + panelDisplayData.getPanelId() + ",\"items\":[";
                List<Integer> items = panelDisplayData.getItems();
                for (int k = 0; k < items.size(); k++) {
                    result += items.get(k);
                    if (k < items.size() - 1) {
                        result += ",";
                    }
                }
                result += "]}";
                if (j < displayData.size() - 1) {
                    result += ",";
                }
            }
            result += "]}";
            if (i < profilesList.size() - 1) {
                result += ",";
            }
        }
        result += "]}";
        return result;
    }
}